/**
 * author:龚佳新  
 * date:2013-08-12
 * 资产结构模型 方法全部抽取 为目前最精简模式
 */
Cnbi.model.Assets= function(params) {
   Cnbi.model.BaseSliderAndProgress.call(this,params); 
   var scope = this,domArray = params["domArray"];
   this.initPage=function(){
	      if(!scope.flag){//alert("子类的initPage");
	      		CnbiSoft.setCurrentRenderer("JavaScript");
	    	}

	   setFormula(false);
	   scope.setSliderValue(params.slider_array, scope.datas, "Idinput");
	   scope.setProgressValue(params.progress_array,scope.datas, "Idspan");
	   this.initChart(true);
	   
	   //scope.flag=true;	   
	   //var msg = "资产结构预测模型【"+scope.defaults["params"]["year"]+"---"+scope.defaults["params"]["month"]+"---"+scope.defaults["params"]["unit"]+"】";
       //scope.updataTitle(msg);     	
    }
    
    /*this.initBefore=function(){
	      for(var i=0;i<scope.zIndicator.length;i++){
			 	var tId = scope["vaprefix"]+scope.zIndicator[i]["id"];
				if(scope.defaults["id"]=="assets"&& scope.defaults["judgeObj"]&&tId==scope.defaults["judgeObj"]["ldzczcv"]){
		               var o = {id:0,vaprefix:scope.vaprefix,datas:scope.datas};
		               scope.getDefinedIndicatorObjResult(o,scope.zIndicator[i]);
		               scope.datas[scope.defaults["judgeObj"]["ldzczcv"]] = o.result;
				}
                if(scope.defaults["id"]=="assets"&& scope.defaults["judgeObj"]&&tId==scope.defaults["judgeObj"]["yysrzcv"]){
		               var o1 = {id:1,vaprefix:scope.vaprefix,datas:scope.datas};
		               scope.getDefinedIndicatorObjResult(o1,scope.zIndicator[i]);
		               scope.datas[scope.defaults["judgeObj"]["yysrzcv"]] = o1.result;
				}
                if(scope.defaults["id"]=="assets"&& scope.defaults["judgeObj"]&&tId==scope.defaults["judgeObj"]["zzcbzv"]){
		               var o2 = {id:2,vaprefix:scope.vaprefix,datas:scope.datas};
		               scope.getDefinedIndicatorObjResult(o2,scope.zIndicator[i]);
		               scope.datas[scope.defaults["judgeObj"]["zzcbzv"]] = o2.result;
				}
				if(scope.defaults["id"]=="assets"&& scope.defaults["judgeObj"]&&tId==scope.defaults["judgeObj"]["zzczzv"]){
		               var o3 = {id:3,vaprefix:scope.vaprefix,datas:scope.datas};
		               scope.getDefinedIndicatorObjResult(o3,scope.zIndicator[i]);
		               scope.datas[scope.defaults["judgeObj"]["zzczzv"]] = o3.result;
				}
			}
    }*/
    this.initChart=function(action){   	  
    	  new Cnbi.model.Chart(getPieChartObj());
    	  console.dir("我进来这里了！！！");
		  var obj1={domId:domArray[0],datas:scope.datas[params["judgeObj"]["zzcbzv"]]-0,range:industryB,title:'总资产报酬率'},
      	  obj2={domId:domArray[1],datas:scope.datas[params["judgeObj"]["zzczzv"]]-0,range:industryZ,title:'总资产周转率'};
    	  
      	  if(action)new Cnbi.model.Chart(getAngularGaugeObj(obj1));//-2.5,1.2,5.6,7.8
    	  if(action)new Cnbi.model.Chart(getAngularGaugeObj(obj2));
    	  }
    	  
    function getPieChartObj(){
    	return {chartType:1,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swfName:"Pie2d",//这个就不用说了吧！  //AngularGauge.swf
	            datas:[{index0:"",index1:""},[{index0:"负债总计",index1:scope.datas[params["judgeObj"]["fzzj"]]},{index0:"流动资产",index1:scope.datas[params["judgeObj"]["ldzc"]]},{index0:"非流动资产",index1:scope.datas[params["judgeObj"]["fldzc"]]},{index0:"所有者权益",index1:scope.datas[params["judgeObj"]["syzqyhj"]]}]],//   scope.datas["fldzc"]显示的数据  注意：规定的数据解析格式
	            domId:domArray[2],//渲染的dom节点
	            percent:true,
	            color:["1C86EE","EEC900","6B8E23","9400D3","FF0000"], //颜色
	          	attributes:'manageResize="1"  showLabels="1" formatNumberScale="0" chartTopMargin="-10" chartLeftMargin="-20"  legendAllowDrag="0" minimiseWrappingInLegend="0" showBorder="0"   legendBorderThickness="0" legendBorderColor="ffffff" legendBorderAlpha="0" bgColor="ffffff" bgAlpha="0,0" showValues="0" isSmartLineSlanted="1" pieSliceDepth="100"  showLegend="0"',//numberPrefix="￥" 
	          	width:"180%",
	          	height:"100%"
	          	}
    };	  
    	  
    function getAngularGaugeObj(params){
     	var range = params["range"],
     	dialsAttr=' radius="70" baseWidth="20" topWidth="2" color="296CAF,000000" fillRatio="90, 10" borderColor="8C7EFF"  valueY="155" ',
        attributes='manageResize="1" showValue="1"  origW="330" showBorder="0" origH="170" showTickValues="0" numberSuffix="%" baseFontColor="000000" animation="1" autoAlignTickValues="1"  tickValueDistance="1" bgColor="FFFFFF" bgAlpha="0" lowerLimit="'+range["lowers"]+'" upperLimit="'+range["excellent"]+'" gaugeStartAngle="180" gaugeEndAngle="0" gaugeOuterRadius="-80" gaugeInnerRadius="100" gaugeOriginX="165" gaugeOriginY="130" minorTMNumber="5" majorTMColor="000000" minorTMColor="000000" majorTMHeight="15" majorTMThickness="1" minorTMHeight="10" minorTMThickness="1" decmials="2" placeValuesInside="1" pivotFillMix="87CEFF, 25588A" pivotFillRatio="50,50" pivotBorderThickness="40" pivotBorderColor="CCCCCC" pivotRadius="15" showShadow="0" toolTipBgColor="FFFFFF"',
    	annotations='<annotationGroup id="Grp1" showBelow="1" x="165" y="131">'+
                   		'<annotation type="arc" x="0" y="7" radius="115" innerRadius="0" startAngle="0" endAngle="180" fillAngle="90" fillRatio="10,90" color="80ACD7, FFFFFF" fillPattern="linear" borderColor="B9CEE2" borderThickness="10" />'+
                   		'<annotation type="circle"  radius="21"  fillAlpha="0" borderColor="" borderThickness="2" borderAlpha="60" />'+
                	'</annotationGroup>',
        trendpoints='<point startValue="'+range["lowers"]+'" endValue="'+range["average"]+'" valueInside="0" color="FF0000" innerRadius="115" alpha="100" />' +
      			  '<point startValue="'+range["average"]+'" endValue="'+range["good"]+'" valueInside="0" color="EEC900" innerRadius="115" alpha="100" />' +
      			  '<point startValue="'+range["good"]+'" endValue="'+range["excellent"]+'" valueInside="0" color="00CD00" innerRadius="115" alpha="100" />',
        styles='<definition><style name="LimitFont" type="font" face="Verdana" size="13"  bold="1"/><style name="pivotGlow" type="glow" color="FFFFFF" /></definition>'+
              '<application><apply toObject="VALUE" styles="LimitFont" /><apply toObject="PIVOT" styles="pivotGlow" /></application>';
        return {chartType:0,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swfName:"AngularGauge",//这个就不用说了吧！  //AngularGauge.swf
	            datas:params["datas"],//显示的数据  注意：规定的数据解析格式  numberSuffix="%"
	            domId:params["domId"],//渲染的dom节点
	            attributes:attributes,
	            color:["FF0000","EEC900","00CD00"], //颜色good 
	            dialsAttr:dialsAttr,
	            styles:styles,
	           // trendpoints:trendpoints,
	            annotations:annotations,
	          	colorRange:[range["lowers"],range["average"],range["good"],range["excellent"]],//chartType==0时才有此属性
	          	width:"90%",height:"40%"};
    };
    
    function updateTip(value){
    	console.dir("我进来这里了看看！！！");
	   if(value<=0){
		  $("#zczkspan").html("<font color='red'>总体来看,虽然流动资产增长慢于主营业务收入增长，但资产的盈利能力没有提高，资产结构有待提高！</font>");
	   }else{
		  $("#zczkspan").html("<font color='green'>总体来看，流动资产增长慢于主营业务收入增长，并且资产的盈利能力有所提高,资产结构趋于改善!。</font>");
	   };
    }
    
    this.updataInputAfter=function(id ,value,datas ){
		
		setFormula(true);   
	};
	
	function setFormula(action) {
		var ldzczcv = params["judgeObj"]["ldzczcv"],
		zcfzv = params["judgeObj"]["zcfzv"],
		//zzcbzv = params["judgeObj"]["zzcbzv"],
		//zzczzv = params["judgeObj"]["zzczzv"],
		yysrzcv = params["judgeObj"]["yysrzcv"];
	   	      
	}
    /**
     * override
     * 如果想要提高效率，则可加联动的判断  
     */
  /* this.updataInputAfter=function(id ,value,datas ){
       if(id=="yysr"){
       		setYysrzzv(true);
        }
      else if(id=="lrze" ||id=="cwfy"){// 
       		setZzcbcv(true);
        }
     else  if(id=="ldzc"){
        	setLdzczzv(true);
        }
      else  if(id=="zczj"){
      		setZzczzv(true);
        	setZcfzv(true);
        	setZzcbcv(true);
        	
        }
       else if(id=="fzzj"){
        	setZcfzv(true);
        	
        }
      
	  //setFormula(true);
   };
   *//**比较期 yysrC=营业收入,ldzchjC=流动资产合计,zczjC=资产合计,fzzjC=负债合计
    * 
    *//*
   function setFormula(action){
          setLdzczzv(action);
          setYysrzzv(action);
          setZcfzv(action);
          setZzcbcv(action);
          setZzczzv(action);
   }
 *//**
  * 流动资产增长率=（流动资产分析期的期末数-流动资产比较期的期末数）/流动资产比较期的期末数*100%--ldzczzv=((((ldzchj- ldzchjbj)/ldzchjbj))*100);
  *//*
   function setLdzczzv(action){
     if(scope.datas.yysrC==0){
     	 scope.datas["ldzczcv"] = 0.00;
     }else{
            scope.datas["ldzczcv"] =Utils.formatFloat((scope.datas.ldzc-scope.datas.ldzchjC)/scope.datas.ldzchjC*100,2);
     }
     updateTip(scope.datas["ldzczcv"]);
     if(action) scope.updataSpanAndProgess("ldzczcv_Idspan");
   }
 *//**
 *营业收入增长率=（营业收入分析期的本期数-营业收入比较期的本期数）/营业收入比较期的本期数*100%--yysrzzv =((((yysrf-yysrb)/yysrb))*100)	 		
  *//*
  function setYysrzzv(action){
  	if(scope.datas.yysrC==0){
  		 scope.datas["yysrzcv"] = 0.00;
  	}else{
  		    scope.datas["yysrzcv"] = Utils.formatFloat((scope.datas.yysr-scope.datas.yysrC)/scope.datas.yysrC*100,2);
  	}
     if(action) scope.updataSpanAndProgess("yysrzcv_Idspan");
  }
 *//**
 *资产负债率=分析期的负债总额的期末数/分析期的资产总额的期末数*100%--zcfzv= ((fzhj/zchj)*100).toFixed(2),//资产负债率 		
  *//*
  function setZcfzv(action){
  	if(scope.datas.zczj==0){
  		 scope.datas["zcfzv"] =0.00;
  	}else{
      scope.datas["zcfzv"] = Utils.formatFloat(scope.datas.fzzj/scope.datas.zczj*100,2);
  	}
     if(action) scope.updataSpanAndProgess("zcfzv_Idspan");
  }  
 *//**
 * 总资产报酬率=均为分析期数据（利润总额累计数+利息支出）/((资产总额年初数+资产总额期末数）/2)；
 * 总资产报酬率=均为分析期数据（利润总额累计数+财务费用累计数）/((资产总额年初数+资产总额期末数）/2)
  *//*
  function setZzcbcv(action){
  	var temp=(scope.datas.zczj+scope.datas.zczjN)/2;
  	if(temp==0){
  	 scope.datas["zzcbzv"]=0.00;
  	}else{
      scope.datas["zzcbzv"] = Utils.formatFloat((scope.datas.lrze+scope.datas.cwfy)/temp,2);
  	}
     // alert("总资产报酬率=="+ scope.datas["zzcbzv"]);
  	if(!isNaN( scope.datas["zzcbzv"])){
  	  if(action)  getChartFromId(domArray[0].toString()+domArray[3].toString()).setData(1, scope.datas["zzcbzv"]);
  	}else{
  	  scope.datas["zzcbzv"]=0.00;
  	}
     
  }
*//**  
 *  总资产增长率=（资产总计分析期的期末数-资产总计比较期的期末数）/资产总计比较期的期末数*100%
 *//*
function setZzczzv(action){//
	if(scope.datas.zczjC==0) scope.datas["zzczzv"]=0.00;
	else scope.datas["zzczzv"] = Utils.formatFloat((scope.datas.zczj-scope.datas.zczjC)/scope.datas.zczjC*100,2);
	
	if(!isNaN( scope.datas["zzczzv"])){
  	   if(action){ getChartFromId(domArray[1].toString()+domArray[3].toString()).setData(1,scope.datas["zzczzv"]);
  	}else{
  	  scope.datas["zzczzv"]=0.00;
  	}
   
     }
      
}  
 var industryB={},  industryZ={};
     this.setBodyDataAfter=function(data){
       industryB = data["zzcbzv"]==undefined?{"average":3.5,"excellent":8.6,"good":5.1,"lowers":-0.2}:data["zzcbzv"];
       industryZ = data["zzczzv"]==undefined?{"average":8.0,"excellent":15.0,"good":10.8,"lowers":2.4}:data["zzczzv"];
    }
     */
   	scope.init();
/*   	var time=2000;
   	if(scope.hasCache){time=1000;}
  	setTimeout(function() {//fadeOut  //sildeIn
	Ext.get("loading").remove();
	Ext.get("loading-mask").fadeOut({remove : true});
	//	e.fadeOut({easing:'easeOut',duration:.5,remove:true,useDisplay:false});
	// e.fadeOut({remove : true})
			}, time);*/
}